<?php

declare(strict_types=1);

namespace App\Core;

final class Flash
{
    public static function success(string $message): void
    {
        $_SESSION['_flash']['success'] = $message;
    }

    public static function error(string $message): void
    {
        $_SESSION['_flash']['error'] = $message;
    }

    public static function warning(string $message): void
    {
        $_SESSION['_flash']['warning'] = $message;
    }

    public static function info(string $message): void
    {
        $_SESSION['_flash']['info'] = $message;
    }

    public static function get(string $type): ?string
    {
        $message = $_SESSION['_flash'][$type] ?? null;
        unset($_SESSION['_flash'][$type]);
        return $message;
    }

    public static function has(string $type): bool
    {
        return isset($_SESSION['_flash'][$type]);
    }

    public static function clear(): void
    {
        unset($_SESSION['_flash']);
    }
}
